﻿using UnityEngine;
using System.Collections;
using COC.Character;

/// <summary>
/// applies to aspect of building,such house,troop camp,hell town,turrent.
/// 用于有关建筑之类，比如房子，兵营，地狱城镇，炮塔。
/// </summary>
namespace COC.Character.Building
{
    public class BaseBuilding : BaseBehaviourSupport
    {
        bool showHeadFlag;
        float distance = 2f;
        // Use this for initialization
        public override void OnStart()
        {
            if (!IsInvoking("ShowHeadStatusFlag"))
            {
                InvokeRepeating("ShowHeadStatusFlag", 2, 1);
            }
            showHeadFlag = true;
        }




        void ShowHeadStatusFlag()
        {
            if (showHeadFlag)
            {
                Vector3 pos = new Vector3(transform.position.x, transform.position.y + distance, transform.position.z);
				//Quaternion rotation=new Quaternion(
				GameObject flag = Instantiate(Resources.Load("Demo/Blue-Flag"), pos, Quaternion.identity) as GameObject;
                flag.transform.parent = this.transform;//attach flag object to this transform as its parent.seems like a dom that is mapping a child to its parent(stem). 
                showHeadFlag = false;
            }
        }


        // call OnDestroy method just after called BaseScript Destroy method. 
        //调用该方法发生在调用BaseScript Destroy方法时发生
        public override void OnDestroy()
        {
            CancelInvoke("ShowHeadStatusFlag");
        }

    }
}